home *** CD-ROM | disk | FTP | other *** search
- 10 'RAND01.BAS - a random file that contains the following:
- 20 'FIRSTNAME$ The first name of the person on file
- 30 'LASTNAME$ The last name of the person on file
- 40 'SOCSEC$ The social security number of the person on file
- 50 '
- 60 'First, set up the fields. We'll use a total record length of 64, and
- 70 'divide it up as follows:
- 80 '
- 90 'FIRSTNAME$ length will be 23
- 100 'LASTNAME$ length will be 30
- 110 'SOCSEC$ length will be 11 (total = 64)
- 120 '
- 130 'First step: open the file and set up the fields...
- 140 '
- 150 OPEN "EMPLOYEE.DAT" FOR RANDOM AS #1 LEN=64
- 160 FIELD #1,23 AS FIRSTNAME$,30 AS LASTNAME$,11 AS SOCSEC$
- 170 '
- 180 'Second step: determine the end of file. If this is the first time that
- 190 'you've entered information, then it will be zero. Otherwise, it will be
- 200 'the record number of the last number...
- 210 '
- 220 LASTRECORD=LOF(1)/64
- 230 '
- 240 'Note we've called the variable that will contain the last record number as
- 250 'LASTRECORD (an easy name to remember), that we used LOF(1) since this is
- 260 'the first file (#1) we've opened, and divided by 64 since this is what we
- 270 'decided to use for a record length.
- 280 '
- 290 'Now, let's get some information to write to the disk file. We'll ask the
- 300 'user if he/she wants to enter information, if the answer is 'Y' then we'll
- 310 'enter the information. If the answer is 'N' then we'll display all the
- 320 'entries currently on disk...
- 330 '
- 340 KEY OFF:CLS
- 350 INPUT "Do you want to enter a record? Answer Y for Yes, N for No";ANSWER$
- 360 IF ANSWER$="Y" OR ANSWER$="y" THEN GOTO 500
- 370 '
- 380 'No more records, so show all entries...
- 390 '
- 400 CLS
- 410 '
- 420 'Here's how easy it is to get information WITHOUT closing the file first!
- 430 '
- 440 FOR RECORD = 1 TO LASTRECORD
- 450 GET #1,RECORD
- 460 PRINT USING "\ \ \ \ \ \";FIRSTNAME$;LASTNAME$;SOCSEC$
- 470 NEXT RECORD
- 480 CLOSE #1
- 490 END
- 500 '
- 510 'User decided to put in records, so let's do so...
- 520 INPUT "What is the FIRST NAME";FIRNAME$
- 530 PRINT
- 540 INPUT "What is the LAST NAME";LASNAME$
- 550 PRINT
- 560 PRINT "(for the SSN, use this format => ###-##-####"
- 570 INPUT "What is the SOCIAL SECURITY NUMBER";SNUMBER$
- 580 '
- 590 'We now have the needed information, so let's put it on disk...
- 600 '
- 610 LSET FIRSTNAME$=FIRNAME$
- 620 LSET LASTNAME$=LASNAME$
- 630 LSET SOCSEC$=SNUMBER$
- 640 '
- 650 'Now, add one to the LASTRECORD so this record is saved after it...
- 660 LASTRECORD=LASTRECORD+1
- 670 PUT #1,LASTRECORD
- 680 '
- 690 'Record stored safely on disk, now see if there are any more to put in...
- 700 GOTO 340
- 710 END
- 720 'End of program - RAND01.BAS
- 730 'From the GW-BASIC TUTORIAL SERIES (GWBT08, 02/01/1991)